package com.linchong.jvm.memory;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2020-11-15 23:08
 * @Description: HeapParams$heap参数设置
 */
@Slf4j
public class HeapParams {

	private byte[] bs = new byte[1024*1024];

	public static void main(String[] args) {
		List<HeapParams> list = new ArrayList<>();
		int num=0;
		try {
			while (true){
				list.add(new HeapParams());
				num++;
			}
		}catch (Throwable err){
			log.info("error occur,num=【{}】",num);
			err.printStackTrace();
		}

		memoryInfo();

	}

	private static void memoryInfo() {
		//字节转M
		log.info("totalMemory:【{}】M",Runtime.getRuntime().totalMemory()/1024.0/1024);
		log.info("freeMemory:【{}】M",Runtime.getRuntime().freeMemory()/1024.0/1024.0);
		log.info("maxMemory:【{}】M",Runtime.getRuntime().maxMemory()/1024.0/1024.0);
	}
}
